module Aio::Parse
  class HasDeviceState < ParentState

    def get_device(opts)
      self.device_manager.add_device(opts)
    end

    def get_full(opts)

      if ! check_full(opts)
        no_full
      elsif
        @machine.to_full_state
      end

    end

    def no_full
    end

    # 验证是否有cmd和context了
    def check_full(opts={})
      device_name = opts[:device_name]
      device_klass = self.device_manager.devices[device_name]

      org_cmd = opts[:cmd]
      org_context = opts[:context]
      org_cmd_reg = Aio::Base::Toolkit::Regexp.to_reg(org_cmd)
      device_klass.cmds_context.each_pair do |cmd, context|

        # 只有当有cmd, 并且context不为空的时候才算有
        # FIXME 可以在这里的context类加入.check_avlid? 查看是否有效
        if org_cmd_reg.match(cmd)
          if ! context.empty?
            return true
          end
        end

      end
      return false
    end

  end
end
